package com.empire.module.rainbow.dal.mysql.diypage;

import com.empire.framework.common.pojo.PageResult;
import com.empire.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.empire.framework.mybatis.core.mapper.BaseMapperX;
import com.empire.module.rainbow.controller.app.diy.vo.AppRainbowDiyPagePageReqVO;
import com.empire.module.rainbow.dal.dataobject.diypage.RainbowDiyPageDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 六彩-装修页面 Mapper
 *
 * @author wudi
 */
@Mapper
public interface RainbowDiyPageMapper extends BaseMapperX<RainbowDiyPageDO> {

    default PageResult<RainbowDiyPageDO> selectPage(AppRainbowDiyPagePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<RainbowDiyPageDO>()
                .eqIfPresent(RainbowDiyPageDO::getTemplateId, reqVO.getTemplateId())
                .likeIfPresent(RainbowDiyPageDO::getName, reqVO.getName())
                .eqIfPresent(RainbowDiyPageDO::getRemark, reqVO.getRemark())
                .eqIfPresent(RainbowDiyPageDO::getPreviewPicUrls, reqVO.getPreviewPicUrls())
                .eqIfPresent(RainbowDiyPageDO::getProperty, reqVO.getProperty())
                .betweenIfPresent(RainbowDiyPageDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(RainbowDiyPageDO::getId));
    }
    default List<RainbowDiyPageDO> selectListByTemplateId(Long templateId) {
        return selectList(RainbowDiyPageDO::getTemplateId, templateId);
    }

    default RainbowDiyPageDO selectByNameAndTemplateIdIsNull(String name) {
        return selectOne(new LambdaQueryWrapperX<RainbowDiyPageDO>()
                .eq(RainbowDiyPageDO::getName, name)
                .isNull(RainbowDiyPageDO::getTemplateId));
    }
}
